package idv.cjcat.stardust.common.particles;

import java.util.Hashtable;
	
	/**
	 * This class represents a particle and its properties.
	 */
	public class Particle {
		
		/**
		 * The initial life upon birth.
		 */
		public float initLife;
		/**
		 * The normal scale upon birth.
		 */
		public float initScale;
		/**
		 * The normal alpha value upon birth.
		 */
		public float initAlpha;
		
		/**
		 * The remaining life of the particle.
		 */
		public float life;
		/**
		 * The scale of the particle.
		 */
		public float scale;
		/**
		 * The alpha value of the particle.
		 */
		public float alpha;
		/**
		 * The mass of the particle.
		 */
		public float mass;
		/**
		 * The mask value of the particle.
		 * 
		 * <p>
		 * The particle can only affected by an action or initializer only if the bitwise AND of their masks is non-zero.
		 * </p>
		 */
		public int mask;
		/**
		 * Whether the particle is marked as dead.
		 * 
		 * <p>
		 * Dead particles would be removed from simulation by an emitter.
		 * </p>
		 */
		public boolean isDead;
		/**
		 * The collision radius of the particle.
		 */
		public float collisionRadius;
		/**
		 * Custom user data of the particle.
		 * 
		 * <p>
		 * Normally, this property contains information for renderers. 
		 * For instance this property should refer to a display object for a <code>DisplayObjectRenderer</code>.
		 * </p>
		 */
		public Object target;
		/**
		 * Particle color.
		 * 
		 * <p>
		 * This information can be used by the <code>PixelRenderer</code> class for determining pixel colors.
		 * </p>
		 */
		public int color;
		/**
		 * The sorted index iterator.
		 */
		public ParticleIterator sortedIndexIterator;
		/**
		 * Dictionary for storing additional information.
		 */
		public Hashtable dictionary;
		
		public Hashtable recyclers;
		
		/*
		private ParticleHandler _handler;
		public final ParticleHandler handler() { return _handler; }
		public final void setHandler(ParticleHandler value) {
			if (value==null) value = ParticleHandler.getSingleton();
			_handler = value;
		}
		*/
		
		public Particle() {
			dictionary = new Hashtable();
			recyclers = new Hashtable();
		}
		
		/**
		 * Initializes properties to default values.
		 * 
		 * <p>
		 * life = 0. scale = 1. alpha = 1. mass = 1. mask = 1. collisoinRadius = 0. target = null. sortedIndex = NaN.
		 * </p>
		 */
		public void init() {
			initLife = life = 0;
			initScale = scale = 1;
			initAlpha = alpha = 1;
			mass = 1;
			mask = 1;
			isDead = false;
			collisionRadius = 0;
			color = 0;
			sortedIndexIterator = null;
			//_handler = ParticleHandler.getSingleton();
		}
		
		public void destroy() {
			target = null;
			//TODO
			dictionary.clear();
			recyclers.clear();
			//_handler = null;
		}
	}